import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '/app/my_app.dart';
import '/flavors/build_config.dart';
import '/flavors/env_config.dart';
import '/flavors/environment.dart';
import 'app/data/local/preference/preference_manager.dart';

void main() async {


  if( !kIsWeb ){
    // web模式下, 没有启动画面
    WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
    // initialization(null);
    // FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
  }

  SharedPreferences preference = await SharedPreferences.getInstance();
  String? token = preference.getString(PreferenceManager.keyToken);

  EnvConfig prodConfig = EnvConfig(
    appName: "数悟空",
    baseUrl: "https://gczn.cn",
    shouldCollectCrashLog: true,
      token: token ?? ""
  );

  BuildConfig.instantiate(
    envType: Environment.PRODUCTION,
    envConfig: prodConfig,
  );
  // 强制横屏显示
  if( !kIsWeb ){
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
  }




  runApp(const MyApp());

  if( !kIsWeb ){

    if (  Platform.isAndroid){
      //状态栏沉浸
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      // SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);

    }
  }
}
